<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">      
  <xsl:output method="html" version="1.0" encoding="ISO-8859-1" omit-xml-declaration="yes"/>

  <xsl:include href="XsltUtils.xslt"/>

  <xsl:decimal-format name="decimal-separator" grouping-separator="." digit="#" zero-digit="0" decimal-separator="," />
  
  <xsl:template name="HeaderStyle">
    <style>

      body {
      font-family: Arial;
      font-size: 12px;
      line-height: 1.5;
      }

      font {
      font-family: Arial;
      font-size: 12px;
      line-height: 1.5;
      }

      table tr td {
      border: none;
      margin: 0px 0px 0px 0px;
      padding: 2px;
      font-family: Arial;
      font-size: 12px;
      line-height: 1.5;
      }

      table tr th {
      border: none;
      margin: 0px 0px 0px 0px;
      padding: 2px;
      line-height: 1.5;
      }


      table {
      border-collapse: collapse;
      }
    </style>
    <head>
      <title>
        <xsl:value-of select="/ProjectDataSet/Project/ProjectName"/>
      </title>
    </head>
  </xsl:template>

  <xsl:template name="IsSuspended">
    <xsl:if test="/ProjectDataSet/Project/IsSuspended='1'">
       (SUSPENDED)
    </xsl:if>
  </xsl:template>

  <xsl:template name="ProjectStatus">
    <xsl:choose>
      <xsl:when test ="/ProjectDataSet/Project/Status='1'">
        Registered
      </xsl:when>
      <xsl:when test ="/ProjectDataSet/Project/Status='2'">
        At Proposal
      </xsl:when>
      <xsl:when test ="/ProjectDataSet/Project/Status='3'">
        Approved
      </xsl:when>
      <xsl:when test ="/ProjectDataSet/Project/Status='4'">
        Rejected
      </xsl:when>
      <xsl:when test ="/ProjectDataSet/Project/Status='5'">
        Running
      </xsl:when>
      <xsl:when test ="/ProjectDataSet/Project/Status='6'">
        Testing
      </xsl:when>
      <xsl:when test ="/ProjectDataSet/Project/Status='7'">
        Maintance
      </xsl:when>
      <xsl:when test ="/ProjectDataSet/Project/Status='8'">
        Done
      </xsl:when>
      <xsl:when test ="/ProjectDataSet/Project/Status='9'">
        Canceled
      </xsl:when>      
    </xsl:choose>
  </xsl:template>

    <xsl:template name="Header">
      
        <table width="600" align="center">
          <tr>
            <td>
              <img src="{/ProjectDataSet/Project/ServerUrl}FactoryService/images/factory/logo.gif"/>

            </td>
            <td width="100%" bgcolor="#e7ebea">

              <table width="100%" height="100%">
                <tr>
                  <td style="font-size: 24px" colspan="2">
                    Factory Alert
                  </td>

                </tr>
                <tr>
                  <td>Project:</td>
                  <td width="100%">
                    <b>
                      <xsl:value-of select="/ProjectDataSet/Project/ProjectName"/> [<xsl:value-of select="/ProjectDataSet/Project/ProjectNumber"/>]
                    </b>
                  </td>
                </tr>
                <tr>
                  <td>Client:</td>
                  <td>
                    <b>
                      <xsl:value-of select="/ProjectDataSet/Project/ClientName"/>
                    </b>
                  </td>
                </tr>
              </table>

            </td>
          </tr>
        </table>
      </xsl:template>

  <xsl:template name="ProjectIdentification">    
    It is identified by <b>
      <a href="{/ProjectDataSet/Project/ClientServerUrl}?ProjectNumber={/ProjectDataSet/Project/ProjectNumber}">
        <xsl:value-of select="/ProjectDataSet/Project/ProjectName"/>
        [<xsl:value-of select="/ProjectDataSet/Project/ProjectNumber"/>]</a>
    </b> from client <b>
      <xsl:value-of select="/ProjectDataSet/Project/ClientName"/>
    </b>.
    <br/>
    <br/>
  </xsl:template>

  <xsl:template name="ProjectDetails">
    Project details:
    <table>
      <tr>
        <td>
          <b>Project Status</b>
        </td>
        <td>
          <xsl:call-template name="ProjectStatus"/>&#160;<xsl:call-template name="IsSuspended"/>
        </td>
      </tr>
      <tr>
        <td>
          <b>Project Type</b>
        </td>
        <td>
          <xsl:value-of select="/ProjectDataSet/Project/Model"/>
        </td>
      </tr>
      <tr>
        <td>
          <b>Project Plataform</b>
        </td>
        <td> 
          <xsl:value-of select="/ProjectDataSet/Project/Plataform"/>
        </td>
      </tr>
      <tr>
        <td valign="top">
          <b>Project Description</b>
        </td>
        <td>
          <xsl:call-template name="MultiLineText">
            <xsl:with-param name="text" select="/ProjectDataSet/Project/Description"/>
          </xsl:call-template>          
        </td>
      </tr>
    </table>
  </xsl:template>

  <xsl:template name="ProjectRoles">
    You will have the follwing guys as your team members:<br/><br/>
    <table>
      <xsl:for-each select="/ProjectDataSet/Project/BacklogItemUnit">
        <xsl:sort select="UnitDescription"/>
        <xsl:variable name="unitName" select="UnitName"/>
        <xsl:if test="count(/ProjectDataSet/Project/ProjectRole[UnitName=$unitName])">
          <tr>
            <td>
              <b>
                <xsl:value-of select="UnitDescription"/>
              </b>
              <ul>
                <xsl:for-each select="/ProjectDataSet/Project/ProjectRole[UnitName=$unitName]">
                  <xsl:sort select="ContactName"/>
                  <li>
                    <xsl:value-of select="ContactName"/>
                    <xsl:if test="ContactEmail != ''">
                      (<xsl:value-of select="ContactEmail"/>)
                    </xsl:if>
                  </li>
                </xsl:for-each>
              </ul>
            </td>
          </tr>        
        </xsl:if>
  
      </xsl:for-each>  
    </table>
    
  </xsl:template>

  <xsl:template name="ProjectIndicators">
    <br/>
    Project Indicators:<br/>
    <table>
      <tr>
        <td>Budget Usage</td>
        <td>
          <big>
            <b>
              <xsl:choose>
                <xsl:when test="/ProjectDataSet/Project/BudgetIndicator &gt; 100">
                  <xsl:value-of select="format-number(number(/ProjectDataSet/Project/BudgetIndicator) - 100,'0,0','decimal-separator')"/>% debit
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="format-number(100 - number(/ProjectDataSet/Project/BudgetIndicator),'0,0','decimal-separator')"/>% profit
                </xsl:otherwise>
              </xsl:choose>
            </b>
          </big>
        </td>
      </tr>
      <tr>
        <td>Deadline</td>
        <td>
          <big>
            <b>
              <xsl:value-of select="format-number(/ProjectDataSet/Project/DeadlineIndicator, '0,0', 'decimal-separator')"/>              
              <xsl:choose>
                <xsl:when test="/ProjectDataSet/Project/DeadlineIndicator &gt; 0">
                  hours ahead
                </xsl:when>
                <xsl:otherwise>
                  hours late
                </xsl:otherwise>
              </xsl:choose>
            </b>
          </big>
        </td>
      </tr>
      <tr>
        <td>
          Quality
        </td>
        <td>
          <big>
            <b>
              <xsl:value-of select="format-number(/ProjectDataSet/Project/QualityIndicator, '0,0', 'decimal-separator')"/>% of re-work hours
            </b>
          </big> 
        </td>
      </tr>
    </table>
  </xsl:template>

  <xsl:template name="Footer">
    <br/>
    You will be notified of any project status change.<br/><br/>

    <a href="{/ProjectDataSet/Project/ClientServerUrl}?ProjectNumber={/ProjectDataSet/Project/ProjectNumber}">
      Click here to see more project details.
    </a>

  </xsl:template>
  
</xsl:stylesheet>